// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.characters.AttachedItems;

import java.util.ArrayList;

public final class AttachedLocationGroup {
    protected final String id;
    protected final ArrayList<AttachedLocation> locations = new ArrayList();

    public AttachedLocationGroup(String _id) {
        if (_id == null) {
            throw new NullPointerException("id is null");
        } else if (_id.isEmpty()) {
            throw new IllegalArgumentException("id is empty");
        } else {
            this.id = _id;
        }
    }

    public AttachedLocation getLocation(String locationId) {
        for (int _int = 0; _int < this.locations.size(); _int++) {
            AttachedLocation attachedLocation = (AttachedLocation)this.locations.get(_int);
            if (attachedLocation.id.equals(locationId)) {
                return attachedLocation;
            }
        }

        return null;
    }

    public AttachedLocation getOrCreateLocation(String locationId) {
        AttachedLocation attachedLocation = this.getLocation(locationId);
        if (attachedLocation == null) {
            attachedLocation = new AttachedLocation(this, locationId);
            this.locations.add(attachedLocation);
        }

        return attachedLocation;
    }

    public AttachedLocation getLocationByIndex(int index) {
        return index >= 0 && index < this.size() ? (AttachedLocation)this.locations.get(index) : null;
    }

    public int size() {
        return this.locations.size();
    }

    public int indexOf(String locationId) {
        for (int _int = 0; _int < this.locations.size(); _int++) {
            AttachedLocation attachedLocation = (AttachedLocation)this.locations.get(_int);
            if (attachedLocation.id.equals(locationId)) {
                return _int;
            }
        }

        return -1;
    }

    public void checkValid(String locationId) {
        if (locationId == null) {
            throw new NullPointerException("locationId is null");
        } else if (locationId.isEmpty()) {
            throw new IllegalArgumentException("locationId is empty");
        } else if (this.indexOf(locationId) == -1) {
            throw new RuntimeException("no such location \"" + locationId + "\"");
        }
    }
}
